package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.domain.EntryInfo;
import com.zjhd.sealcutting.domain.ExhibitionInfo;
import com.zjhd.sealcutting.domain.UserInfo;
import com.zjhd.sealcutting.param.CreativeTaskSearchQuery;
import com.zjhd.sealcutting.param.EntrySearchQuery;
import com.zjhd.sealcutting.service.EntryInfoService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import com.zjhd.sealcutting.vo.SearchResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO 词条管理
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/26 17:52
 */
@Api(value = "词条管理", tags = "词条管理")
@RequestMapping("/entryInfo")
@RestController
public class EntryInfoController {

    private final static Logger logger = LoggerFactory.getLogger(EntryInfoController.class);

    @Autowired
    private EntryInfoService entryInfoService;

    @ApiOperation(value = "分页查询词条列表接口", notes = "分页查询词条列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue = "10", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", defaultValue = "1", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryEntryParamlist")
    public ResponseResult<SearchResult<EntryInfo>> queryEntryParamlist(EntrySearchQuery param){
        try{
            return ResultGenerator.genSuccessResult(entryInfoService.queryEntryParamlist(param));
        }catch (Exception ex) {
            logger.error("分页查询词条列表接口失败", ex);
            return ResultGenerator.genFailResult("分页查询词条列表接口失败");
        }
    }

    @ApiOperation(value = "查询用户所分配词条", notes = "查询用户所分配词条接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/queryByUserNameEntry")
    @OperLog(operModul = "展览管理-查询词条",operType = "查询",operDesc = "查询用户所分配词条")
    public ResponseResult<List<EntryInfo>> queryByUserNameEntry(Integer userId){
        try{
            return ResultGenerator.genSuccessResult(entryInfoService.queryByUserNameEntry(userId));
        }catch (Exception ex) {
            logger.error("查询用户所分配词条接口失败", ex);
            return ResultGenerator.genFailResult("查询用户所分配词条接口失败");
        }
    }

    @ApiOperation(value = "新增词条", notes = "新增词条接口")
    @PostMapping("/insertEntry")
    @OperLog(operModul = "词条管理-新增词条",operType = "新增",operDesc = "新增词条")
    public ResponseResult insertEntry(@RequestBody EntryInfo entryInfo){
        try{
            return ResultGenerator.genSuccessResult(entryInfoService.insertEntry(entryInfo));
        }catch (Exception ex) {
            logger.error("新增词条接口失败", ex);
            return ResultGenerator.genFailResult("新增词条接口失败");
        }
    }

    @ApiOperation(value = "修改词条", notes = "修改词条接口")
    @PostMapping("/updateEntry")
    @OperLog(operModul = "词条管理-修改词条",operType = "修改",operDesc = "修改词条")
    public ResponseResult updateEntry(@RequestBody EntryInfo entryInfo){
        try{
            return ResultGenerator.genSuccessResult(entryInfoService.updateEntry(entryInfo));
        }catch (Exception ex) {
            logger.error("修改词条接口失败", ex);
            return ResultGenerator.genFailResult("修改词条接口失败");
        }
    }

    @ApiOperation(value = "查询词条详情", notes = "查询词条详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "词条ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/queryByIdEntry")
    @OperLog(operModul = "词条管理-查询词条",operType = "查询",operDesc = "查询词条详情")
    public ResponseResult queryByIdEntry(Integer id){
        try{
            return ResultGenerator.genSuccessResult(entryInfoService.queryByIdEntry(id));
        }catch (Exception ex) {
            logger.error("查询词条详情接口失败", ex);
            return ResultGenerator.genFailResult("查询词条详情接口失败");
        }
    }

    @ApiOperation(value = "删除词条", notes = "删除词条接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "词条ID", dataType = "Long", paramType = "query")
    })
    @PostMapping("/delEntry")
    @OperLog(operModul = "词条管理-删除词条",operType = "删除",operDesc = "删除词条")
    public ResponseResult delEntry(@RequestParam(value = "id",defaultValue = "")Integer id){
        try{
            return ResultGenerator.genSuccessResult(entryInfoService.delEntry(id));
        }catch (Exception ex) {
            logger.error("删除词条接口失败", ex);
            return ResultGenerator.genFailResult("删除词条接口失败");
        }
    }
}
